export interface ModelConfigInfo {
  id: string;
  providerId: string;
  providerName: string;
  baseUrl: string;
  apiKey: string;
  displayApiKey?: string;  // 掩码版本的API密钥，用于UI显示
  modelName: string;
  displayName?: string;
  isActive: boolean;
  status: 'healthy' | 'unhealthy' | 'checking' | 'unknown';
  lastChecked?: Date;
  createdAt: Date;
  updatedAt?: Date;
  // 扩展配置
  maxTokens?: number;
  temperature?: number;
  topP?: number;
  frequencyPenalty?: number;
  presencePenalty?: number;
  // 元数据
  description?: string;
  tags?: string[];
  version?: string;
  costPerToken?: number;
  // 监控数据
  responseTime?: number;
  errorCount?: number;
  uptime?: number; // 小时
  healthScore?: number; // 0-100
  lastError?: string;
  // API密钥关联
  keyId?: string;
  keyStatus?: 'active' | 'inactive' | 'expired';
  keyExpiresAt?: Date;
  usageStats?: {
    totalUsage: number;
    dailyUsage: number;
    monthlyUsage: number;
    remainingQuota: number;
    lastUsedAt?: Date;
  };
}

export interface ModelTemplate {
  providerId: string;
  providerName: string;
  defaultBaseUrl: string;
  suggestedModels: SuggestedModel[];
  authType?: 'bearer' | 'apikey' | 'oauth';
  authDescription?: string;
  documentation?: string;
}

export interface SuggestedModel {
  name: string;
  displayName: string;
  description: string;
  maxTokens?: number;
  costPerToken?: number;
  capabilities?: string[];
  isRecommended?: boolean;
}

export interface ModelConfigRequest {
  providerId: string;
  providerName: string;
  baseUrl: string;
  apiKey: string;
  modelName: string;
  displayName?: string;
  isActive?: boolean;
}

export interface ModelConfigResponse {
  success: boolean;
  data?: ModelConfigInfo;
  error?: string;
  message?: string;
}

export interface ModelTestResult {
  success: boolean;
  status: 'healthy' | 'unhealthy';
  responseTime?: number;
  error?: string;
  message: string;
  modelInfo?: {
    name: string;
    version?: string;
    maxTokens?: number;
    capabilities?: string[];
  };
}

export interface ModelConfigListResponse {
  success: boolean;
  data?: ModelConfigInfo[];
  total?: number;
  page?: number;
  pageSize?: number;
  error?: string;
}

export interface ModelDiscoveryResult {
  providerId: string;
  models: Array<{
    name: string;
    displayName?: string;
    description?: string;
    maxTokens?: number;
    deprecated?: boolean;
  }>;
  lastUpdated: Date;
}

// 配置验证规则
export interface ValidationRule {
  field: keyof ModelConfigInfo;
  type: 'required' | 'url' | 'pattern' | 'length';
  message: string;
  pattern?: RegExp;
  min?: number;
  max?: number;
}

// 模型配置状态
export type ModelStatus = 'healthy' | 'unhealthy' | 'checking' | 'unknown';

// 提供商类型
export type ProviderType = 
  | 'openai' 
  | 'claude' 
  | 'deepseek' 
  | 'qwen' 
  | 'wenxin' 
  | 'spark' 
  | 'kimi' 
  | 'doubao' 
  | 'hunyuan'
  | 'custom';

// 配置事件类型枚举
export enum ConfigEventType {
  CREATED = 'created',
  UPDATED = 'updated',
  DELETED = 'deleted',
  TESTED = 'tested',
  ACTIVATED = 'activated',
  DEACTIVATED = 'deactivated'
}

export interface ConfigEvent {
  type: ConfigEventType;
  configId: string;
  timestamp: Date;
  changes?: Partial<ModelConfigInfo>;
  result?: ModelTestResult;
}

// API密钥集成类型
export interface ModelConfigWithKey extends ModelConfigInfo {
  encryptedKey?: string;
  keyRotationDue?: boolean;
  keyAuditLogs?: AuditLog[];
}

export interface AuditLog {
  id: string;
  action: string;
  userId: string;
  timestamp: Date;
  details?: any;
}